package com.mojiayi.learn.swagger2.controller;

import com.alibaba.fastjson.JSONObject;
import com.mojiayi.learn.swagger2.model.Course;
import com.mojiayi.learn.swagger2.system.config.ApiTags;
import io.swagger.annotations.*;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

@Api(value = "课程基本信息控制接口")
@RestController
@RequestMapping("/course")
public class CourseController {
    @ApiOperation(value = "获取课程详情", notes = "根据课程id查询课程详情", tags = {ApiTags.COURSE_MANAGEMENT})
    @RequestMapping(value = "getDetail", method = RequestMethod.GET)
    public JSONObject getDetail(@ApiParam(name = "id", value = "课程id", required = true) Long id) {
        JSONObject courseObject = new JSONObject();
        courseObject.put("id", id);
        courseObject.put("title", "测试课程");
        return courseObject;
    }

    @ApiOperation(value = "提交新课程", notes = "新建课程或修改课程后提交", tags = {ApiTags.COURSE_MANAGEMENT})
    @ApiResponse(code = 123, message = "", examples = @Example({@ExampleProperty(
            value = "{\"id\",123}",
            mediaType = MediaType.APPLICATION_JSON_UTF8_VALUE
    )}))
    @RequestMapping(value = "submitCourse", method = RequestMethod.POST)
    public JSONObject submitNewCourse(Course course) {
        JSONObject courseObject = new JSONObject();
        courseObject.put("id", course.getId());
        courseObject.put("title", course.getTitle());
        courseObject.put("price", course.getPrice());
        return courseObject;
    }
}
